package sunwin.yoms.web.comm;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import sunwin.yoms.service.security.YomsUserDetails;

/**
 * Created by 田西泽 on 2015-8-14.
 */
@Component
public class YomsControllerDefaultData {
    public YomsUserDetails getCurrentYomsUserDetails() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null) {
            Object obj = authentication.getPrincipal();
            if (obj.getClass() == YomsUserDetails.class) {
                YomsUserDetails userDetails = (YomsUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
                return userDetails;
            }
        }
        return null;
    }
}
